package cn.com.zpark;

import cn.com.zpark.bean.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @PackageName: cn.com.zpark
 * @ClassName: ServletDemo01
 * @Description:
 * @author: RZS
 * @date: 2021/11/28  16:48
 */
@WebServlet("/s1.do")
public class ServletDemo01 extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 获取session对象
        HttpSession session = request.getSession();

        User user = new User();
        user.setName("张三");
        user.setPwd("123456");
        session.setAttribute("user", user);

        List<User> list = new ArrayList<>();
        list.add(user);
        session.setAttribute("lists", list);

        Map<String, String> map = new HashMap<>();
        map.put("name", "大锤");
        map.put("pwd", "root");
        session.setAttribute("maps", map);

        // 重定向到el02.jap 页面
        response.sendRedirect(getServletContext().getContextPath()+"/jsp/el02.jsp");

    }
}
